//////   Consumer.java   //////

public class Consumer extends Thread {
	public Consumer(Cirbuf b) {
		buffer = b;
	}

	public int count() {
		return wcnt;
	}

	public void run() {
		consume();
	}

	public  void consume() {
		char[] c = new char[1];
		while (buffer.get(c)){
			// while more input
			switch (c[0]) {
			case ' ':
			case '\t':
			case '\r':
			case '\n': // word delimiters
				if (word) {
					wcnt++; // word ends
					word = false;
				}
				break;
			default:
				word = true; // word begins
			}
		}
		if (word)
			wcnt++;
		
	}

	private boolean word = false; // partial word indicator
	private int wcnt = 0; // whole words counted so far
	private Cirbuf buffer;
}
